package Terminal.TechnicalServices.Mapper;

import Terminal.Entity.Dominio.ETimeRecord;
import Terminal.Entity.IceClasses.ETimeRecordI;

public class MTimeRecord implements Mapper{

	@Override
	public ETimeRecordI getIceObj(Object hibObj) {

		ETimeRecordI iceTimeRecord = null;
		MMoney moneyMapper = new MMoney();
		MConsulente consulenteMapper = new MConsulente();		
		
		if ( hibObj instanceof ETimeRecord)
		{
			iceTimeRecord = new ETimeRecordI();
			
			iceTimeRecord.id = ((ETimeRecord) hibObj).getId();
			iceTimeRecord.testo = ((ETimeRecord) hibObj).getTesto();
			iceTimeRecord.corrente = ((ETimeRecord) hibObj).getCorrente();
			
			iceTimeRecord.consulente = consulenteMapper.getIceObj( ((ETimeRecord) hibObj).getConsulente() );
			
			iceTimeRecord.costo = moneyMapper.getIceObj( ((ETimeRecord) hibObj).getCosto() );
			iceTimeRecord.costoOrario = moneyMapper.getIceObj( ((ETimeRecord) hibObj).getCostoOrario() );
			
			iceTimeRecord.fine = ((ETimeRecord) hibObj).getFine();
			iceTimeRecord.inizio = ((ETimeRecord) hibObj).getInizio();
		}
		
		return iceTimeRecord;
	}

	@Override
	public ETimeRecord getHibObj(Object iceObj) {

		ETimeRecord hibTimeRecord = null;
		MMoney moneyMapper = new MMoney();
		MConsulente consulenteMapper = new MConsulente();		
		
		if ( iceObj instanceof ETimeRecordI)
		{
			hibTimeRecord = new ETimeRecord();
			
			hibTimeRecord.setId( ((ETimeRecordI) iceObj).id );
			hibTimeRecord.setTesto( ((ETimeRecordI) iceObj).testo );
			hibTimeRecord.setCorrente( ((ETimeRecordI) iceObj).corrente );			
			
			hibTimeRecord.setConsulente( consulenteMapper.getHibObj( ((ETimeRecordI) iceObj).consulente) );

			hibTimeRecord.setCosto( moneyMapper.getHibObj( ((ETimeRecordI) iceObj).costo) );
			hibTimeRecord.setCostoOrario( moneyMapper.getHibObj( ((ETimeRecordI) iceObj).costoOrario) );
			
			hibTimeRecord.setFine( ((ETimeRecordI) iceObj).fine );
			hibTimeRecord.setInizio( ((ETimeRecordI) iceObj).inizio );
			
			hibTimeRecord.calcolaCosto();
		}
		
		return hibTimeRecord;
		
	}	
	
}
